//
//  OPMrestListCell.m
//  OnePiece
//
//  Created by wsy on 15/10/29.
//  Copyright © 2015年 wsy. All rights reserved.
//

#import "OPMrestListCell.h"
#import <UIImageView+WebCache.h>
@implementation OPMrestListCell

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        _picture = [[UIImageView alloc]initWithFrame:CGRectMake(10, 0, SCREEN_WIDTH -20, (SCREEN_WIDTH -20)*290/600)];
        [self.contentView addSubview:_picture];
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(10, (SCREEN_WIDTH -20)*290/600-20, SCREEN_WIDTH-20, 20)];
        view.backgroundColor = [UIColor colorWithWhite:0.000 alpha:0.418];
        [self.contentView addSubview:view];
        _cityAndName = [[UILabel alloc]initWithFrame:CGRectMake(15, (SCREEN_WIDTH -20)*290/600-20, SCREEN_WIDTH-150, 20)];
        _cityAndName.font = [UIFont systemFontOfSize:12];
        _cityAndName.textColor = [UIColor whiteColor];
        [self.contentView addSubview:_cityAndName];
        _desc = [[UILabel alloc]initWithFrame:CGRectMake(10, (SCREEN_WIDTH -20)*290/600+10, SCREEN_WIDTH-20, 60)];
        _desc.numberOfLines = 0;
        _desc.font = [UIFont systemFontOfSize:13];
        [self.contentView addSubview:_desc];
        
    }
    return  self;
}

- (void)setModel:(OPMrestListModel *)model
{
    [_picture sd_setImageWithURL:[NSURL URLWithString:model.cover] placeholderImage:[UIImage imageNamed:@"beijingImg.jpg"]];
    _cityAndName.text = [NSString stringWithFormat:@"%@   %@",model.city, model.name];
    _desc.text = model.desc;
    _desc.frame = CGRectMake(10, (SCREEN_WIDTH -20)*290/600+10, SCREEN_WIDTH-20, [OPMrestListCell heightOfString:model.desc]);
    NSInteger count = [model.key integerValue];
    for (int i = 0; i < count; i++) {
        UIImageView *pic = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-100+i*30, (SCREEN_WIDTH -20)*290/600-18, 15, 15)];
        pic.layer.cornerRadius = 7.5;
        pic.layer.masksToBounds = YES;
        pic.image = [UIImage imageNamed:@"Mbiaozhi.jpg"];
        [self.contentView addSubview:pic];
    }
}

+ (CGFloat)heightOfString:(NSString *)str
{
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:13] forKey:NSFontAttributeName];
    CGRect bounds = [str boundingRectWithSize:CGSizeMake(SCREEN_WIDTH - 20, 0) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:dic context:nil];
    return bounds.size.height;
}

+ (CGFloat)heightForCell:(OPMrestListModel *)model
{
    return (SCREEN_WIDTH -20)*290/600+20+[OPMrestListCell heightOfString:model.desc];
}


@end
